package org.example.annotation;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAspect {
    @Pointcut("execution(* org..TransferService02.*(..))")
    public void pointcut() {
    }

    @Before("pointcut()")
    public void before(JoinPoint joinPoint) throws Throwable {
        System.out.println("【AOP -- before】业务处理之前，连接点：" +
                joinPoint.getSignature().getName());
    }

    @After("pointcut()")
    public void after(JoinPoint joinPoint) throws Throwable {
        System.out.println("【AOP -- after】业务处理之后，连接点：" +
                joinPoint.getSignature().getName());
    }
//
//    @AfterReturning(pointcut = "pointcut()", returning = "returnValue")
//    public void afterReturning(JoinPoint joinPoint, Integer returnValue) throws Throwable {
//        System.out.println("【AOP -- after returning】业务处理之后，连接点：" +
//                joinPoint.getSignature().getName() + ", 返回值：" + returnValue);
//    }
//
//    @AfterThrowing(value = "pointcut()", throwing = "exception")
//    public void afterThrowing(JoinPoint joinPoint, Exception exception) throws Throwable {
//        System.out.println("【AOP -- after Throwing】连接点：" +
//                joinPoint.getSignature().getName() + ", 抛出异常：" + exception.getMessage());
//    }
//
//    @Around("pointcut()")
//    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
//        System.out.println("【AOP -- around】 连接点：" + joinPoint.getSignature().getName());
//        System.out.println("【AOP -- around（before）】 执行业务之前");
//        Object result = joinPoint.proceed();
//        System.out.println("【AOP -- around（after）】 执行业务之后，返回值：" + result);
//    }
}
